package com.tianji.promotion.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.promotion.domain.dto.CouponFormDTO;
import com.tianji.promotion.domain.dto.CouponIssueFormDTO;
import com.tianji.promotion.domain.query.CouponQuery;
import com.tianji.promotion.domain.vo.CouponDetailVO;
import com.tianji.promotion.domain.vo.CouponPageVO;
import com.tianji.promotion.domain.vo.CouponVO;
import com.tianji.promotion.service.ICouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 优惠券的规则信息 前端控制器
 * </p>
 *
 * @author ffk
 * @since 2024-07-02
 */
@Api("优惠券相关接口")
@RestController
@RequiredArgsConstructor
@RequestMapping("/coupons")
public class CouponController {

    private  final ICouponService couponService;

    @ApiOperation("新增优惠券")
    @PostMapping()
    public void addCoupon(@RequestBody @Valid CouponFormDTO couponFormDTO){
        couponService.addCoupon(couponFormDTO);
    }

    @ApiOperation("分页查询优惠券")
    @GetMapping("/page")
    public PageDTO<CouponPageVO> pageQueryCoupon(CouponQuery couponQuery){
        return couponService.pageQueryCoupon(couponQuery);
    }

    @ApiOperation("发放优惠券")
    @PutMapping("/{id}/issue")
    public  void giveSomeCoupon(@PathVariable Long id,@RequestBody CouponIssueFormDTO couponIssueFormDTO){
        couponService.giveSomeCoupon(id,couponIssueFormDTO);
    }

    @ApiOperation("修改优惠券")
    @PutMapping("/{id}")
    public void updateCoupon(@RequestBody CouponFormDTO couponFormDTO){
        couponService.updateCoupon(couponFormDTO);
    }
    @ApiOperation("删除优惠券")
    @DeleteMapping("/{id}")
    public void deleteCoupon(@PathVariable Long id){
        couponService.deleteById(id);
    }

    @ApiOperation("根据id查询优惠券")
    @GetMapping("/{id}")
    public CouponDetailVO getCouponById(@PathVariable Long id){
        return couponService.getCouponById(id);
    }

    @ApiOperation("暂停发放优惠券")
    @PutMapping("/{id}/pause")
    public void pauseCoupon(@PathVariable Long id){
        couponService.pauseCoupon(id);
    }

    @ApiOperation("查询发放中的优惠券列表")
    @GetMapping("/list")
    public List<CouponVO> queryIssuingCoupons(){
        return couponService.queryIssuingCoupons();
    }
}
